package com.dongdongshop.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.TbBrandService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
@RequestMapping("brand")
public class BrandController {
    @Reference
    private TbBrandService  tbBrandService;

    @RequestMapping("toBrand")
    public String toBrand(){
        return "admin/brand";
    }
    @RequestMapping("findAll")
    @ResponseBody
    public Result toFindAll(){
         List<TbBrand> tbBrandList =  tbBrandService.findAll();
         return new Result<List<TbBrand>>(10000,"操作成功",tbBrandList);
    }
    //增加   //收一个boolean类型不够通用,业务失败正能表示失败或者成功,信息不够全
    @ResponseBody
    @RequestMapping("addAll")
    public Boolean addAll (TbBrand tbBrand){
         return tbBrandService.addAll(tbBrand);
    }
    //回显
    @RequestMapping("echo/{id}")
    @ResponseBody
    public TbBrand toUpdate(@PathVariable("id")Integer id){
        TbBrand result = tbBrandService.selectBrandById(id);
        return result;
    }
    //修改
    @ResponseBody
    @RequestMapping("toupdate")
    public Boolean toUpdate(TbBrand tbBrand){
         return tbBrandService.updateAll(tbBrand);
    }
    //删除
    @RequestMapping("deleteBatch")
    @ResponseBody
    public Boolean toDeleteBatch(Integer [] ids) {
        return tbBrandService.deleteBath(ids);
    }
}
